/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.p2psimulator.entity.overlaynetwork.routingtable;

import java.util.Vector;
import org.p2psimulator.entity.Id;
import org.p2psimulator.entity.overlaynetwork.structures.StormWitnessRing;
import org.p2psimulator.entity.reputation.Reputation;

/**
 *
 * @author Amorim
 */
public class WitnessesTable extends ChordRoutingTable<Reputation>{

    private int d;

    private Id referredServentId;

    public WitnessesTable(int M, Id referredServentId, Id owner) {
        super(M, new StormWitnessRing(M), owner);
        this.d = M;
        this.referredServentId = referredServentId;
    }

    
    public void insertWitness(Id peer, Reputation rep){
        StormWitnessRing ring = (StormWitnessRing) fingers;
        if (fingers.size()<=d){
                fingers.insertNode(peer, rep);
        }else{
            ring.removeOlder();
            ring.insertNode(peer, rep);
        }
    }

    public int getD() {
        return d;
    }

    public void setD(int d) {
        this.d = d;
    }

    public Id getReferredServentId() {
        return referredServentId;
    }

    public void setReferredServentId(Id referredServentId) {
        this.referredServentId = referredServentId;
    }

    public Vector<Id> getWitnesses() {
        return fingers.getNodes();
    }

    @Override
    public void insertNode(Id peer, Reputation value) {
        insertWitness(peer, value);
    }

}
